﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Library;

namespace Sport_Shop
{
    public partial class Index : System.Web.UI.Page
    {
        
        static PagedDataSource p = new PagedDataSource();
        public static int intSTT;
        public static int trang_thu = 0;
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                trang_thu = 0;
                load_page();
            }

        }

        private void load_page()
        {
            List<Library.SanPham> ListSP = new List<Library.SanPham>();
            ListSP = Library.SanPham.GetList();

            p.DataSource = ListSP;
            p.PageSize = 4;
            p.CurrentPageIndex = trang_thu;
            p.AllowPaging = true;

            btDau.Enabled = true; btTruoc.Enabled = true; btSau.Enabled = true; btCuoi.Enabled = true;

            if (p.IsFirstPage == true)
            {
                btDau.Enabled = false;
                btTruoc.Enabled = false;
                btSau.Enabled = true;
                btCuoi.Enabled = true;
            }
            if (p.IsLastPage == true)
            {
                btDau.Enabled = true;
                btTruoc.Enabled = true;
                btSau.Enabled = false;
                btCuoi.Enabled = false;
            }
            tbTrang.Text = (trang_thu + 1) + "/" + p.PageCount;
            dlSanpham.DataSource = p;
            dlSanpham.DataBind();
            
        }

        protected void btDau_Click(object sender, EventArgs e)
        {
            trang_thu = 0;
            load_page();
        }

        protected void btTruoc_Click(object sender, EventArgs e)
        {
            trang_thu--;
            load_page();
        }

        protected void btSau_Click(object sender, EventArgs e)
        {
            trang_thu++;
            load_page();
        }

        protected void btCuoi_Click(object sender, EventArgs e)
        {
            trang_thu = p.PageCount - 1;
            load_page();
        }


    }
}